package com.globallogic.training.vaskulg.binarytree;

import static org.junit.Assert.*;

import org.junit.Before;
import org.junit.Test;

public class BinaryTreeHeightTester {
	private BinaryTree<String> testTree;

	@Before
	public void setUp() throws Exception {
		testTree = new BinaryTree<String>("Value of Root Node");
	}
	
	@Test
	public void shouldHaveCorrectHeightWhenOnlyRoot() {
		assertEquals(1, testTree.getHeight());
	}
	
	@Test
	public void shouldHaveCorrectHeightWhenRightHiherThenLeft() {
		// Given
		testTree.addLeftNode("Second Level Node");
		testTree.moveLeft();
		
		testTree.addLeftNode("Third Level Node");
		testTree.moveLeft();
		
		testTree.moveToParent();
		testTree.moveToParent();
		
		testTree.addRightNode("Second Level Node");
		testTree.moveRight();
		
		testTree.addRightNode("Third Level Node");
		testTree.moveRight();
		
		testTree.addRightNode("Forth Level Node");
		
		assertEquals(4, testTree.getHeight());
	}
	
	@Test
	public void shouldHaveCorrectHeightWhenMaxHeightIsInTheMiddle() {
		// Given
		testTree.addLeftNode("Second Level Node");
		testTree.moveLeft();
		
		testTree.addLeftNode("Third Level Node");
		testTree.moveLeft();
		
		testTree.moveToParent();
		
		testTree.addRightNode("Third Level Node");
		testTree.moveRight();
		
		testTree.addLeftNode("4th Level Node");
		testTree.moveLeft();
		
		testTree.addRightNode("5th Level Node");
		testTree.moveRight();
		
		testTree.moveToParent();
		testTree.moveToParent();
		testTree.moveToParent();
		testTree.moveToParent();
		
		testTree.addRightNode("Second Level Node");
		testTree.moveRight();
		
		testTree.addRightNode("Third Level Node");
		testTree.moveRight();
		
		testTree.addRightNode("Forth Level Node");
		
		// Then
		assertEquals(5, testTree.getHeight());
	}
}
